package com.yileiqian.alg;

public class RobotFindWay {

	public static Integer[][] RobotFindWay(boolean matrix[][]) {
		Integer[][] path = new Integer[matrix.length][matrix[0].length];

		for (int x = 0; x < matrix.length; x++) {
			if (matrix[x][0]) {
				path[x][0] = 1;
			} else {
				break;
			}
		}

		for (int y = 0; y < matrix[0].length; y++) {
			if (matrix[0][y]) {
				path[0][y] = 1;
			} else {
				break;
			}
		}

		for (int x = 1; x < matrix.length; x++) {
			for (int y = 1; y < matrix[x].length; y++) {
				if (matrix[x][y]) {
					path[x][y] = path[x - 1][y] + path[x][y - 1];
				}
			}
		}

		return path;
	}

	public static void printMatrix(Object[][] om) {
		StringBuffer buffer = new StringBuffer();
		for (int i = 0; i < om.length; i++) {
			for (int j = 0; j < om[i].length; j++) {
				buffer.append(om[i][j]);
				buffer.append(' ');
			}
			buffer.append('\n');
		}

		System.out.println(buffer);
	}

	public static void main(String args[]) {
		boolean[][] m = new boolean[3][3];
		for(int i = 0;i < 3;i++){
			for(int j = 0; j < 3;j++){
				m[i][j] = true;
			}
		}
		printMatrix(RobotFindWay(m));
	}
}
